﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Scan
{
    public partial class frmSelectSb : Form
    {
        private int ModeValue = 0;
        public frmSelectSb(int modeValue)
        {
            InitializeComponent();
            ModeValue = modeValue;
        }

        private void frmSelectSb_Load(object sender, EventArgs e)
        {
            if (ModeValue == 2)
            {
                comboBox1.Visible = false;
                textBox1.Visible = true;
                textBox1.Location = new Point(27, 46);
                label1.Text = "请输入备注信息：";
            }

            if (ModeValue == 1)
            {
                comboBox1.Visible = true;
                textBox1.Visible = false;
            }

            if (PublicVar.SeiBei == SeiBeiClass.baoxun)
            {
                comboBox1.SelectedItem = comboBox1.Items[0];
            }
            else if (PublicVar.SeiBei == SeiBeiClass.xindalu)
            {
                comboBox1.SelectedItem = comboBox1.Items[1];
            }
            else if (PublicVar.SeiBei == SeiBeiClass.AutoIDOne)
            {
                comboBox1.SelectedItem = comboBox1.Items[2];
            }
            else if (PublicVar.SeiBei == SeiBeiClass.AutoID)
            {
                comboBox1.SelectedItem = comboBox1.Items[3];
            }
            else
            {
                comboBox1.SelectedItem = comboBox1.Items[4];
            }
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            if (ModeValue == 1)
            {
                string a = comboBox1.Text;
                if (MessageBox.Show("您选择的设备是 " + a + " ，确定吗？", "提示") == DialogResult.Yes)
                {
                    
                    edit_config.ConfigSetValue("SeiBeiName", a);

                    if (a == "新大陆")
                    {
                        PublicVar.SeiBei = SeiBeiClass.xindalu;
                    }
                    else if (a == "宝迅")
                    {
                        PublicVar.SeiBei = SeiBeiClass.baoxun;
                    }
                    else if (a == "东大集成一维")
                    {
                        PublicVar.SeiBei = SeiBeiClass.AutoIDOne;
                    }
                    else if (a == "东大集成")
                    {
                        PublicVar.SeiBei = SeiBeiClass.AutoID;
                    }
                    else
                    {
                        PublicVar.SeiBei = SeiBeiClass.YinDaJuLi;
                    }

                    MessageBox.Show("保存成功!");
                }
                this.Close();
            }

            if (ModeValue == 2)
            {
                if (string.IsNullOrEmpty(textBox1.Text.Trim()))
                {
                    MessageBox.Show("请输入备注信息!");
                    return;
                }

                PublicVar.BeiZhu = textBox1.Text.Trim();

                MessageBox.Show("保存成功!");
                this.Close();
            }
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}